/*
 * @Description:
 * @Date: 2024-04-11 16:32:11
 * @LastEditTime: 2024-04-23 15:58:32
 */
import _MessageBox from './index.vue'

export default {
    install(Vue) {
        let messageBox = null;

        Vue.component(_MessageBox.name, _MessageBox);

        Vue.prototype.$messageBox = {
            show,
            hide
        }
        function show(props, cb) {

            if (!messageBox) {
                const MessageBox = Vue.extend({
                    render(h) {
                        return h('message-box', { props })
                    }
                })

                messageBox = new MessageBox();
                this.vm = messageBox.$mount();
                document.getElementById('map').appendChild(this.vm.$el);

                cb && cb();
            }
        }

        function hide(cb) {

            if (this.vm?.$el || (document.getElementById('map') && document.getElementById('map').contains(this.vm?.$el) ) ) {
                document.getElementById('map').removeChild(this.vm.$el)
                messageBox.$destory;
                messageBox = null;
                this.vm = null;
                cb && cb();
            } else {
                return
            }

        }
    }
}
